package com.groupbuying.common.baseutils.baseframework4plugins.message;

import java.nio.charset.StandardCharsets;
import java.util.Locale;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;

/**
 * @anthor zmlmagic
 * @date 2018/12/25 5:23 PM
 * @company 蒙泰互联网公司
 * @des 读取message配置
 **/

@Configuration
public class MessageHelper {
    public static String getMessage(String msgId) {
        String region = "_zh_CN";
        String[] path = {
                "messages/customermgr/CustomerTitle" + region,
                "messages/customermgr/CustomerLoginTitle" + region,
                "messages/customermgr/CustomerError" + region,
                "messages/customermgr/CustomerFindPwdError" + region,
                "messages/customermgr/CustomerFindPwdTitle" + region,
                "messages/customermgr/CustomerRegisterError" + region,
                "messages/customermgr/CustomerRegisterTitle" + region,
                "messages/customermgr/UcenterCustomerTitle" + region,
                "messages/customermgr/CustomerAccountError" + region,
                "messages/customermgr/CustomerTagError" + region,
                "messages/customermgr/CustomerSecurityQuestionError" + region,
                "messages/customermgr/CustomerWelfareTitle" + region,
                "messages/store/StoreConsumerProtectTitle" + region,
                "messages/store/ProtectionProductRelTitle" + region,
                "messages/store/ProtectionStoreRelTitle" + region,
                "messages/store/StoreError" + region,
                "messages/store/StorePubTitle" + region,
                "messages/store/ShopNavigationTitle" + region,
                "messages/store/storecapitalvirtualaccountTitle" + region,
                "messages/store/StoreWithdrawalsError" + region,
                "messages/store/StoreTitle" + region,
                "messages/store/StoreWithdrawalsError" + region,
                "messages/order/Order" + region,
                "messages/yinshen/yspay"

        };


        ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
        messageSource.setCacheSeconds(-1);
        messageSource.setDefaultEncoding(StandardCharsets.UTF_8.name());
        messageSource.setBasenames(path);
        String message = "";
        try {
            Locale locale = LocaleContextHolder.getLocale();
            message = messageSource.getMessage(msgId, null, locale.CHINA);
        } catch (Exception e) {
            return "获取message失败";
        }
        return message;
    }

}

